<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>车辆调度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body class="layui-layout-body">


<blockquote class="layui-elem-quote"  >
    <div class=" layui-form" >
        <div class="layui-form-item"  >


            <div class="layui-input-inline" style="width: 100px">
                <select name="" lay-verify="required" id="khSearchKind" lay-filter="khSearchKind" >
                    <option value="khjc">客户简称</option>
                    <option value="khzjm">助记码</option>
                </select>

                <select name="" lay-filter="dingdan" id="ddSearchKind" >
                    <option value="ydzt">运单状态</option>
                    <option value="ydh">运单号</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select   class="layui-input" id="khSearchContent" lay-search> <option value="">请选择</option></select>

                <div id="ydh" style="display: none" ><select   class="layui-input"  id="ydhSearchContent" lay-search><option value="">请选择</option></select></div>
                <div id="ydzt"  >
                    <select name="" lay-verify="required" id="ddSearchContent">
                        <option value="">选择运单状态</option>
                        <option value="待调度">待调度</option>
                        <option value="待发车">待发车</option>
                        <option value="已发车">已发车</option>
                        <option value="审核中">审核中</option>
                    </select>
                </div>
            </div>



            <div class="layui-input-inline" style="width: 100px">
                <select name="city"  id="xlSearchKind" lay-filter="xlSearchKind" >
                    <option value="xlmc">线路名称</option>
                    <option value="xlzjm">助记码</option>
                </select>
                <select name="city" lay-verify="required" id="qySearchKind" lay-filter="qySearchKind">
                    <option value="qymc">区域名称</option>
                    <option value="qyzjm">助记码</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select   class="layui-input" id="xlSearchContent" lay-search> <option value="">请选择</option></select>
                <select   class="layui-input" id="qySearchContent" lay-search> <option value="">请选择</option></select>

            </div>

            <div class="layui-input-inline" style="width: 100px">
                <label class="layui-form-label">运单起始日期</label>
                <label class="layui-form-label">运单结束日期</label>
            </div>
            <div class="layui-input-inline">
                <input type="text"  class="layui-input"   id="searchQsrqContent">
                <input type="text"  class="layui-input" id="searchJsrqContent">
            </div>


            <div class="layui-input-inline" style="width: 80px">
                <button class="layui-btn layui-btn-normal" id="search">点击搜索</button>
                <button type="button" class="layui-btn layui-btn-normal" id="all">显示全部</button>
            </div>






        </div>
    </div>
</blockquote>
<div class="layui-row">
    <div class="layui-col-xs12">



            <script type="text/html" id="opera">

                {{#  if(d.ydzt == '待调度'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
                <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>

                <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
                {{# }else if(d.ydzt == '待发车'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="startcar">发车</button>
                <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
                {{# }else if(d.ydzt == '已发车'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
                <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>

                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="posterror">退回</button>
                {{# }else if(d.ydzt.split('_')[1] == '审核中'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</button>
                <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="startcar">发车</button>

                <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="posterror">退回</button>
                {{# } }}


        </script>
        <table id="table" lay-filter="Table"></table>
        <script type="text/html" id="selectTpl_type">
            {{d.cph}}
        </script>
        <script type="text/html" id="selectOrderType">
            {{d.leixing}}
        </script>
        <script type="text/html" id="ydztfix">
            {{# if(d.ydzt.indexOf('_') != -1){ }}
            {{d.ydzt.split('_')[1]}}
            {{#   }else{ }}
            {{d.ydzt }}
            {{# } }}
        </script>
    </div>
</div>




<script src="../js/tools.js"></script>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['form' ,'table','jquery','layer','element','laydate'], function(){
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;
        var element = layui.element;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var tableheight=  'full-130';
        var tablewidth = 90;
        var currentPage = 1;
        var cphData=[];
        var leixingData=[];
        var elemNull = {};
        // elemNull.value = "&nbsp";
        // elemNull.text = "&nbsp";
        // cphData[0] = elemNull;
        //获取类型Data

         var leixingArr = ['带货','放空','来回','套跑','公司配货'];
            $.each(leixingArr,function (i,e) {
                var elem = {};
                elem.value = e;
                elem.text = e;
                leixingData[i+1] = elem;
            })
        //获取 cphData
        $.ajax({
            url: contextPath+"/car",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                for(var i in res.list){
                    if(res.list[i].sffp == "未分配"){
                        var elem = {};
                        elem.value = res.list[i].clid;
                        elem.text = res.list[i].cph;
                        cphData[i+1] = elem;
                    }
                }

                console.log(cphData);
            }

        });

        //搜索的运单状态还是运单号

        form.on('select(dingdan)',function (data) {
            if(data.value == "ydh"){
                $("#ydzt").css("display","none");
                $("#ydh").css("display","block");
                $("#ydhSearchContent").empty();
                $.ajax({
                    url: contextPath+"/waybill?bd=dd",
                    type: "GET",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        $("#ydhSearchContent").append("<option value=''>请选择</option>");
                        for(var i in res.list){
                            var option = "<option value='"+ res.list[i].ydh+ "'>"+res.list[i].ydh+"</option>";
                            $("#ydhSearchContent").append(option);
                        };
                        form.render('select');
                    }
                });
            }else if(data.value == "ydzt"){
                $("#ydh").css("display","none");
                $("#ydzt").css("display","block");

            }
        });



        //  渲染搜索 select
        yewuSearch(form,$);

        //执行一个laydate实例
        laydate.render({
            elem: '#ydrq' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });
        laydate.render({
            elem: '#searchQsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'
        });
        laydate.render({
            elem: '#searchJsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });



//请求车牌号




        //刷新table实例
        $("#all").on('click',function () {
            $.ajax({
                url: contextPath+"/waybill?bd=dd",
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {
                    table.render({
                        elem: '#table'
                        ,height:tableheight
                        ,data:res.list
                        ,page: {
                            curr: currentPage //重新从第 1 页开始
                        } //开启分页
                        ,limit:10
                        ,id:'table'
                        ,cellMinWidth: tablewidth
                        ,cols: [[ //表头
                            {type:'numbers', title: '序号',  align:'center'}
                            ,{field: 'ydh', title: '运单号' ,align:'center'}
                             ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                            ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                            ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                            ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                            ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                            ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                            ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                            ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                            ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                            ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                            ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                        ]]

                        ,done: function(res, curr, count){
                            //得到当前页码
                            console.log(curr);
                            currentPage = curr;
                        }
                    });
                }

            });

        });
//初始化表格
        $.ajax({
            url: contextPath+"/waybill?bd=dd",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                table.render({
                    elem: '#table'
                    ,height:tableheight
                    ,data:res.list
                    ,page: {
                        curr: currentPage //重新从第 1 页开始
                    } //开启分页
                    ,limit:10
                    ,id:'table'
                    ,cellMinWidth: tablewidth
                    ,cols: [[ //表头
                        {type:'numbers', title: '序号',  align:'center'}
                        ,{field: 'ydh', title: '运单号' ,align:'center'}
                         ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                        ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                        ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                        ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                        ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                        ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                        ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                        ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                        ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                        ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                        ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                        ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                    ]]

                    ,done: function(res, curr, count){
                        //得到当前页码
                        console.log(curr);
                        currentPage = curr;
                    }
                });
            }

        });

//监听单元格编辑

        // table.on('edit(Table)',function (obj) {
        //
        //         var value = obj.value //得到修改后的值
        //             ,data = obj.data //得到所在行所有键值
        //             ,field = obj.field; //得到字段
        //         layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
        // });
//监听表格

        table.on('tool(Table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(obj.data.ydzt == "调度_审核中" || obj.data.ydzt == "快捷_审核中" || obj.data.ydzt == "报账_审核中" || obj.data.ydzt == "登记_审核中"){
                obj.data.ydzt = "审核中";
            }
            if(obj.data.ydzt == "快捷_已完成"){
                obj.data.ydzt = "已完成";
            }
            if(layEvent === 'detail'){
                console.log(data);
                layer.open({
                    // cancel: function(index, layero){
                    //     var faIndex = index;
                    //     layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title:'提示'}, function(index){
                    //         //do something
                    //         layer.close(index);
                    //         layer.close(faIndex);
                    //     });
                    //     return false
                    // },
                    type: 2,
                    title: '查看运单信息',
                    maxmin: true,
                    //点击遮罩关闭层
                    shadeClose:true,
                    area : ['80%' , '60%'],
                    content: ['./lookVeSch.html','no'],
                    success:function(layero,index){
                        console.log(data);
                        var body = layer.getChildFrame('body',index);

                        for(var i in data){
                            body.contents().find("[name='"+i+"']").val(eval("data."+i));
                        }
                    },
                    end:function(){

                    }
                });
            } else if(layEvent === 'delete'){
                layer.confirm('确定删除？', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        url: contextPath+"/waybill/"+data.ydid,
                        type: "DELETE",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            layer.msg(res.message);
                            $.ajax({
                                url: contextPath+"/waybill?bd=dd",
                                type: "GET",
                                contentType:"application/json;charset=utf-8",
                                dataType:"json",
                                success: function(res) {
                                    table.render({
                                        elem: '#table'
                                        ,height:tableheight
                                        ,data:res.list
                                        ,page: {
                                            curr: currentPage //重新从第 1 页开始
                                        } //开启分页
                                        ,limit:10
                                        ,id:'table'
                                        ,cellMinWidth: tablewidth
                                        ,cols: [[ //表头
                                            {type:'numbers', title: '序号',  align:'center'}
                                            ,{field: 'ydh', title: '运单号' ,align:'center'}
                                            ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                            ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                            ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                            ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                            ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                            ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                            ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                            ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                            ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                            ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                            ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                        ]]

                                        ,done: function(res, curr, count){
                                            //得到当前页码
                                            console.log(curr);
                                            currentPage = curr;
                                        }
                                    });
                                }

                            });
                        }
                    });
                });
            }else if(layEvent === 'startcar'){

                $.ajax({
                    url: contextPath+"/waybill/"+data.ydid,
                    type: "PUT",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        layer.msg(res.message);

                        // obj.update({
                        //     ydzt: '调度_已发车'
                        // });
                        $.ajax({
                            url: contextPath+"/waybill?bd=dd",
                            type: "GET",
                            contentType:"application/json;charset=utf-8",
                            dataType:"json",
                            success: function(res) {
                                table.render({
                                    elem: '#table'
                                    ,height:tableheight
                                    ,data:res.list
                                    ,page: {
                                        curr: currentPage //重新从第 1 页开始
                                    } //开启分页
                                    ,limit:10
                                    ,id:'table'
                                    ,cellMinWidth: tablewidth
                                    ,cols: [[ //表头
                                        {type:'numbers', title: '序号',  align:'center'}
                                        ,{field: 'ydh', title: '运单号' ,align:'center'}
                                         ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                        ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                        ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                        ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                        ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                        ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                        ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                        ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                        ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                        ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                        ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                        ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                    ]]

                                    ,done: function(res, curr, count){
                                        //得到当前页码
                                        console.log(curr);
                                        currentPage = curr;
                                    }
                                });
                            }

                        });
                    }
                });

            }else if(layEvent === 'posterror') {

                layer.open({
                    cancel: function (index, layero) {
                        var faIndex = index;
                        layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                            //do something
                            layer.close(index);
                            layer.close(faIndex);
                        });
                        return false
                    },
                    type: 2,
                    title: '退回',
                    maxmin: true,
                    //点击遮罩关闭层
                    area: ['1200px', '450px'],
                    content: ['./postErrordd.html', 'no'],
                    success: function (layero, index) {
                        console.log(data);
                        var body = layer.getChildFrame('body', index);

                        for (var i in data) {
                            body.contents().find("[name='" + i + "']").val(eval("data." + i));
                        }
                    },
                    end: function () {
                        $.ajax({
                            url: contextPath+"/waybill?bd=dd",
                            type: "GET",
                            contentType:"application/json;charset=utf-8",
                            dataType:"json",
                            success: function(res) {
                                table.render({
                                    elem: '#table'
                                    ,height:tableheight
                                    ,data:res.list
                                    ,page: {
                                        curr: currentPage //重新从第 1 页开始
                                    } //开启分页
                                    ,limit:10
                                    ,id:'table'
                                    ,cellMinWidth: tablewidth
                                    ,cols: [[ //表头
                                        {type:'numbers', title: '序号',  align:'center'}
                                        ,{field: 'ydh', title: '运单号' ,align:'center'}
                                        ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                        ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                        ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                        ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                        ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                        ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                        ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                        ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                        ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                        ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                        ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                        ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                    ]]

                                    ,done: function(res, curr, count){
                                        //得到当前页码
                                        console.log(curr);
                                        currentPage = curr;
                                    }
                                });
                            }

                        });
                    }
                });
            }
            else if(obj.event === 'cph'){
                console.log(obj);
                //渲染下拉列表
                (function($,doc,o){
                    var tk;
                    var obj;
                    var otd;
                    var callback;
                    o.show = function(h,e,c){
                        callback = c;
                        var d =  doc.getElementById('table_type_select');
                        if(d){
                            d.remove();
                        }
                        otd = e;
                        var s = '<div id="table_type_select" class="table-select"><dl class="layui-anim layui-anim-downbit" style="padding: 0px;top: 0px">';
                                s+= '<input is_input="1" id="table_type_select_input"  class="layui-input" type="text">';
                        for(var k in h.data){

                                s += '<dd lay-value="'+ h.data[k].value + '" >'+ h.data[k].text + '</dd>';

                        }
                        s += '</dl></div>';
                        otd.innerHTML = s + otd.innerHTML;
                        obj = doc.getElementById('table_type_select');
                        //console.log($(obj));
                        obj.onmouseout = function(){
                            tk = 1;
                            setTimeout(function() {
                                if(tk){
                                    if(obj){
                                        ke = 0;
                                        obj.remove();
                                        callback({value:"",text:""});
                                    }
                                }
                            }, 200);
                        }
                        obj.onmouseover = function(){
                            tk = 0;
                        }
                        obj.addEventListener('click', function(e){

                            if($(e.srcElement).attr('is_input')){
                                 $("#table_type_select_input").focus(); //聚焦
                                 e.stopImmediatePropagation(); //阻止冒泡
                                $("#table_type_select_input").bind("input propertychange",function(){ //获取输入内容
                                    $("#table_type_select dd").each(function (i,elem) {
                                        if( $(this).html().indexOf($("#table_type_select_input").val()) == -1){
                                            console.log(i + $(this).html() );
                                            $(this).css("display","none");
                                        }else {
                                            $(this).css("display","");
                                        }
                                    });
                                    console.log("--------" );
                                });
                            }else {
                                var value = $(e.srcElement).attr('lay-value');
                                var text = e.srcElement.innerHTML;
                                obj.remove();
                                callback({value:value,text:text});
                            }
                        });
                    }
                })($,document, window.type_select = {});

                if(obj.data.ydzt != "已发车"){//判断是否发车
                    type_select.show({
                        //设置当前选择的id
                        value:obj.data.cph,
                        //下拉选择数据
                        data:cphData}, this, function(e){
                        //回调函数 返回结果

                             var objData = {};
                            objData.clid = e.value;
                            objData.ydid = data.ydid;

                            console.log(objData);
                            $.ajax({
                                url: contextPath+"/waybill/cph",
                                type: "PUT",
                                contentType:"application/json;charset=utf-8",
                                dataType:"json",
                                data:JSON.stringify(objData),
                                success: function(res) {
                                    obj.data.cph = e.text;

                                    obj.update(obj.data);
                                    // layer.msg(res.message);

                                    $.ajax({
                                        url: contextPath + "/waybill?bd=dd",
                                        type: "GET",
                                        contentType: "application/json;charset=utf-8",
                                        dataType: "json",
                                        success: function (res) {
                                            table.render({
                                                elem: '#table'
                                                , height: tableheight
                                                , data: res.list
                                                , page: {
                                                    curr: currentPage //重新从第 1 页开始
                                                } //开启分页
                                                , limit: 10
                                                , id: 'table'
                                                , cellMinWidth: tablewidth
                                                , cols: [[ //表头
                                                    {type:'numbers', title: '序号',  align:'center'}
                                                    ,{field: 'ydh', title: '运单号' ,align:'center'}
                                                     ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                                    ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                                    ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                                    ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                                    ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                                    ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                                    ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                                    ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                                    ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                                    ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                                    ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                                    ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                                ]]

                                                , done: function (res, curr, count) {
                                                    //得到当前页码
                                                    console.log(curr);
                                                    currentPage = curr;
                                                }
                                            });
                                        }

                                    });
                                }
                            });

                        form.render();
                    });
                }else {
                    layer.msg("本单已经发车！");
                }
            } else if(obj.event === 'leixing'){
                console.log(obj);
                //渲染下拉列表
                (function($,doc,o){
                    var tk;
                    var obj;
                    var otd;
                    var callback;
                    o.show = function(h,e,c){
                        callback = c;
                        var d =  doc.getElementById('table_type_select2');
                        if(d){
                            d.remove();
                        }
                        otd = e;
                        var s = '<div id="table_type_select2" class="table-select"><dl class="layui-anim layui-anim-downbit" style="padding: 0px;top: 0px">';
                        //   s+= '<input is_input="1" id="table_type_select_input"  class="layui-input" type="text">';
                        for(var k in h.data){

                            s += '<dd lay-value="'+ h.data[k].value + '" >'+ h.data[k].text + '</dd>';

                        }
                        s += '</dl></div>';
                        otd.innerHTML = s + otd.innerHTML;
                        obj = doc.getElementById('table_type_select2');
                        //console.log($(obj));
                        obj.onmouseout = function(){
                            tk = 1;
                            setTimeout(function() {
                                if(tk){
                                    if(obj){
                                        ke = 0;
                                        obj.remove();
                                        callback({value:"",text:""});
                                    }
                                }
                            }, 200);
                        }
                        obj.onmouseover = function(){
                            tk = 0;
                        }
                        obj.addEventListener('click', function(e){

                            var value = $(e.srcElement).attr('lay-value');
                            var text = e.srcElement.innerHTML;
                            obj.remove();
                            callback({value:value,text:text});

                        });
                    }
                })($,document, window.type_select = {});

                if(obj.data.ydzt != "已发车"){//判断是否发车
                    type_select.show({
                        //设置当前选择的id
                        value:obj.data.leixing,
                        //下拉选择数据
                        data:leixingData}, this, function(e){
                        //回调函数 返回结果

                        var objData = {};
                        objData.leixing = e.value;
                        objData.ydid = data.ydid;

                        console.log(objData);
                        $.ajax({
                            url: contextPath+"/waybill/type",
                            type: "PUT",
                            contentType:"application/json;charset=utf-8",
                            dataType:"json",
                            data:JSON.stringify(objData),
                            success: function(res) {
                                obj.data.leixing = e.text;

                                obj.update(obj.data);
                                // layer.msg(res.message);

                                $.ajax({
                                    url: contextPath + "/waybill?bd=dd",
                                    type: "GET",
                                    contentType: "application/json;charset=utf-8",
                                    dataType: "json",
                                    success: function (res) {
                                        table.render({
                                            elem: '#table'
                                            , height: tableheight
                                            , data: res.list
                                            , page: {
                                                curr: currentPage //重新从第 1 页开始
                                            } //开启分页
                                            , limit: 10
                                            , id: 'table'
                                            , cellMinWidth: tablewidth
                                            , cols: [[ //表头
                                                {type:'numbers', title: '序号',  align:'center'}
                                                ,{field: 'ydh', title: '运单号' ,align:'center'}
                                                ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                                ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                                ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                                ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                                ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                                ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                                ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                                ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                                ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                                ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                                ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                                ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                            ]]

                                            , done: function (res, curr, count) {
                                                //得到当前页码
                                                console.log(curr);
                                                currentPage = curr;
                                            }
                                        });
                                    }

                                });
                            }
                        });

                        form.render();
                    });
                }else {
                    layer.msg("本单已经发车！");
                }
            }

        });

        // table.on('edit(Table)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
        //
        //     console.log(obj);
        // });



//搜索
        $("#search").on('click',function () {
            if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() != ""){
                if(!checkEndTime($("#searchQsrqContent").val(),$("#searchJsrqContent").val())){
                    layer.msg("起始日期大于结束日期!");
                }else {
                    var url = contextPath+"/waybill?"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+"ydzt"+"="+$("#ddSearchContent").val().toString()+ "&ydh="+ $("#ydhSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val();
                    console.log(url+"&bd=dd");
                    $.ajax({
                        url: url+"&bd=dd" ,
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            table.render({
                                elem: '#table'
                                ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                                ,data:res.list
                                ,page: true //开启分页
                                ,limit:10
                                ,cellMinWidth: tablewidth
                                ,cols: [[ //表头
                                    {type:'numbers', title: '序号',  align:'center'}
                                    ,{field: 'ydh', title: '运单号' ,align:'center'}
                                     ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                    ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                    ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                    ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                    ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                    ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                    ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                    ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                    ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                    ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                    ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                    ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                                ]]
                            });
                        }
                    });
                }
            } else if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() == ""){
            layer.msg("结束日期不能为空！");
        }else if($("#searchQsrqContent").val() == "" && $("#searchJsrqContent").val() != ""){
            layer.msg("起始日期不能为空！");
        }else {
                var url = contextPath+"/waybill?"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+"ydzt"+"="+$("#ddSearchContent").val()+ "&ydh="+ $("#ydhSearchContent").val();
                console.log(url);
                $.ajax({
                    url: url+"&bd=dd" ,
                    type: "GET",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        table.render({
                            elem: '#table'
                            ,height:tableheight
//                    ,url:  contextPath+"/"//数据接口
                            ,data:res.list
                            ,page: true //开启分页
                            ,limit:10
                            ,cellMinWidth: tablewidth
                            ,cols: [[ //表头
                                {type:'numbers', title: '序号',  align:'center'}
                                ,{field: 'ydh', title: '运单号' ,align:'center'}
                                 ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center'}

                                ,{field: 'khjc', title: '客户简称' ,  align:'center'}

                                ,{field: 'qymc', title: '区域名称' ,  align:'center'}
                                ,{field: 'xlmc', title: '线路名称' ,  align:'center'}
                                ,{field: 'ydrq', title: '运单日期' ,align:'center'}

                                ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,  }
                                ,{field: 'cllx', title: '车辆类型' ,align:'center'}
                                ,{field: 'jsyxm', title: '驾驶员' ,align:'center'}
                                ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
                                ,{field: 'leixing', templet: '#selectOrderType',title: '类型' ,align:'center',event: 'leixing'}
                                ,{field: 'llcyje', title: '理论充油金额' ,align:'center'}
                                ,{ title:'操作', align:'center', toolbar: '#opera',width:200}
                            ]]
                        });
                    }
                });
            }
        });


    });





</script>
</body>
</html>